package com.jlnk.stockdemo.bean;

import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;
import java.util.List;

public class SpotListResponse {

    @SerializedName("request_id")
    private String requestId;

    @SerializedName("code")
    private int code;

    @SerializedName("data")
    private Data data;

    @SerializedName("msg")
    private String msg;

    public String getRequestId() {
        return requestId;
    }

    public int getCode() {
        return code;
    }

    public Data getData() {
        return data;
    }

    public String getMsg() {
        return msg;
    }

    public static class Data {
        @SerializedName("fields")
        private List<String> fields;

        @SerializedName("items")
        private List<List<String>> items;

        @SerializedName("has_more")
        private boolean hasMore;

        @SerializedName("count")
        private int count;

        private List<Spot> spotList;

        public List<String> getFields() {
            return fields;
        }

        public List<List<String>> getItems() {
            return items;
        }

        public boolean isHasMore() {
            return hasMore;
        }

        public int getCount() {
            return count;
        }

        public List<Spot> getSpotList() {
            spotList = new ArrayList<>();
            int tsCodeIndex, ts_nameIndex, trade_typeIndex, t_unitIndex, trade_modeIndex, margin_rateIndex;
            tsCodeIndex = ts_nameIndex = trade_typeIndex = t_unitIndex = trade_modeIndex = margin_rateIndex = 0;
            for (int i = 0; i < fields.size(); i++) {
                switch (fields.get(i)) {
                    case "ts_code" :
                        tsCodeIndex = i;
                        break;
                    case "ts_name" :
                        ts_nameIndex = i;
                        break;
                    case "trade_type" :
                        trade_typeIndex = i;
                        break;
                    case "t_unit" :
                        t_unitIndex = i;
                        break;
                    case "trade_mode" :
                        trade_modeIndex = i;
                        break;
                    case "margin_rate" :
                        margin_rateIndex = i;
                        break;
                }
            }
            for (int j = 0; j < items.size(); j++) {
                Spot spot = new Spot();
                spot.setTsCode(items.get(j).get(tsCodeIndex));
                spot.setTs_name(items.get(j).get(ts_nameIndex));
                spot.setTrade_type(items.get(j).get(trade_typeIndex));
                spot.setT_unit(items.get(j).get(t_unitIndex));
                spot.setTrade_mode(items.get(j).get(trade_modeIndex));
                spot.setMargin_rate(items.get(j).get(margin_rateIndex));
                spotList.add(spot);
            }
            return spotList;
        }

        public static class Spot {
            private String tsCode;
            private String ts_name;
            private String trade_type;
            private String t_unit;
            private String trade_mode;
            private String margin_rate;

            public String getTsCode() {
                return tsCode;
            }

            public void setTsCode(String tsCode) {
                this.tsCode = tsCode;
            }

            public String getTs_name() {
                return ts_name;
            }

            public void setTs_name(String ts_name) {
                this.ts_name = ts_name;
            }

            public String getTrade_type() {
                return trade_type;
            }

            public void setTrade_type(String trade_type) {
                this.trade_type = trade_type;
            }

            public String getT_unit() {
                return t_unit;
            }

            public void setT_unit(String t_unit) {
                this.t_unit = t_unit;
            }

            public String getTrade_mode() {
                return trade_mode;
            }

            public void setTrade_mode(String trade_mode) {
                this.trade_mode = trade_mode;
            }

            public String getMargin_rate() {
                return margin_rate;
            }

            public void setMargin_rate(String margin_rate) {
                this.margin_rate = margin_rate;
            }
        }
    }
}
